package web.binder;

import Commons.enums.Gender;

import java.beans.PropertyEditorSupport;

public class CustomGenderPropertyEditor extends PropertyEditorSupport {
    private String gender_boy;

    private String gender_girl;

    private Gender gender;

    public CustomGenderPropertyEditor(String gender_boy, String gender_girl ){
        this.gender_boy =gender_boy;
        this.gender_girl=gender_girl;
    }

    @Override
    public void setAsText(String text) throws IllegalArgumentException {
//        super.setAsText(text);
        if(text.equals(gender_boy)){
            setValue(Gender.男);
            this.gender=Gender.男;
        } else if(text.equals(gender_girl)){
            setValue(Gender.女);
            this.gender=Gender.女;
        }
    }

    @Override
    public String getAsText() {
        if(this.gender.equals(Gender.男)){
            return "男";
        }
        if(this.gender.equals(Gender.女)){
            return "女";
        }
        return null;
    }
}
